using System.IO;
using System.Linq;
using HQLAddin.Highlighting.Classificators;
using HQLAddin.Tests.SnapshotUtils;
using Microsoft.VisualStudio.Text.Classification;
using Moq;
using NUnit.Framework;
using SharpTestsEx;

namespace HQLAddin.Tests.Highlighting
{
    [TestFixture]
    public class KeywordClassifierTest
    {
		[Test]
		public void WhenKeywordIsOutsideOfQueryTagThenReturnsEmpty()
		{
			string[] withKeywordsAsTag = File.ReadAllLines("examples\\WithKeywordsOutsideQuerytag.xml");
			var snapshotSpan = SnapshotUtil.CreateSnapshot(withKeywordsAsTag).CreateSpanFromLineNumber(11);
			var keywordClassifier = new KeywordClassifier(new Mock<IClassificationTypeRegistryService>().Object);
			keywordClassifier.GetClassificationSpans(snapshotSpan).Should().Be.Empty();
		}

		[Test]
		public void WhenKeywordIsInCommentThenReturnsEmpty()
		{
			string[] withKeywordsAsTag = File.ReadAllLines("examples\\WithKeywordsOutsideQuerytag.xml");
			var snapshotSpan = SnapshotUtil.CreateSnapshot(withKeywordsAsTag).CreateSpanFromLineNumber(13);
			var keywordClassifier = new KeywordClassifier(new Mock<IClassificationTypeRegistryService>().Object);
			keywordClassifier.GetClassificationSpans(snapshotSpan).Should().Be.Empty();
		}

		[Test]
		public void RegexContainsAnExpressionThatMatch(
			[Values("order", "insert", "set", "delete", "update", "having")]string word)
		{
			var parameterClassifier = new KeywordClassifier(new Mock<IClassificationTypeRegistryService>().Object);
			parameterClassifier.Regexs.Satisfy(rs => rs.Any(r => r.IsMatch(word)));

		}
	}
}
